#include "libsleep.h"
#include "CTCodeConvert3.h"

CTLIB_SO_FUNC(CAppSleep)

CAppSleep::CAppSleep()
{

}

CAppSleep::~CAppSleep()
{

}

int CAppSleep::Init(void *pData)
{
    CT_ASSERT(pData);
    return 0;
}

int CAppSleep::Do(const CEnpNetHead& stHead, const char* pszReqBuf, int iReqLen, 
                  char* pszAnsBuf, int iAnsBufLen, int& iAnsLen)
{
    CT_TRACE(("RecvMsg: len=%d msg=%s AnsBufLen=%d", iReqLen, pszReqBuf, iAnsBufLen));

    //解析头部
    m_stDecodeStream.Attach((char*)pszReqBuf, (unsigned short)(iReqLen & 0xFFFF));
    CodeConvert(m_stDecodeStream, m_stMsgHead, NULL, string_decode());

    CT_INFO(("sleep"));
    sleep(5);

    m_stEncodeStream.Attach((char*)pszAnsBuf, (unsigned short)(iAnsBufLen & 0xFFFF));
    m_stMsgHead.shMsgType = EMT_ANSWER;
    CodeConvert(m_stEncodeStream, m_stMsgHead, NULL, string_encode());
    memcpy(pszAnsBuf + m_stEncodeStream.m_ushPos, pszReqBuf + m_stDecodeStream.m_ushPos, iReqLen - m_stDecodeStream.m_ushPos);
    iAnsLen = m_stEncodeStream.m_ushPos + iReqLen - m_stDecodeStream.m_ushPos;
    CT_INFO(("ans len = %d, %s", iAnsLen, pszAnsBuf));

    return RET_OK;
}

int CAppSleep::Exit()
{
    return RET_OK;
}





